﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
  class WorkflowsAdaptor : Adaptor, IRefreshable
  {
    private WorkflowCollection workflows;
    public WorkflowsAdaptor(WorkflowCollection workflows)
    {
      this.workflows = workflows;
    }

    public override string Text
    {
      get 
      {
        return "Workflows (" + workflows.Count + ")";
      }
    }

    public override object Object
    {
      get 
      {
        return workflows; 
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 2;
      }
    }

    public override Control GetRenderer()
    {
      WorkflowsControl control = new WorkflowsControl();
      control.LoadWorkflows(workflows);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (Workflow wf in workflows)
      {
        // versions
        TreeNode wfNode = TreeNodeFactory.CreateTreeNode(new WorkflowAdaptor(wf));
        node.Nodes.Add(wfNode);
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      workflows.Refresh();
    }

    #endregion
  }
}
